package com.ruoyi.hr.controller.hr.contractmanage;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.Ztree;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.hr.domain.Authority;
import com.ruoyi.hr.service.AuthorityService;
import com.ruoyi.hr.service.contractmanage.ContractManageService;
import com.ruoyi.hr.util.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author zeo
 * @explain 合同管理
 * @date 2020/3/23
 */
@Controller
@RequestMapping("/contractManage")
public class ContractManageController extends BaseController {

    @Autowired
    ContractManageService contractManageService;

    @Autowired
    AuthorityService authorityService;

    private String prefix = "hr/contractmanage";

    /**
     * 跳转分页页面
     */
    @GetMapping()
    public String contractManage() {
        return prefix + "/contractManage";
    }

    /**
     * 欢迎
     */
    @GetMapping("/welcome")
    public String welcome() {
        return prefix + "/welcome";
    }

    /**
     * 加载薪资管理左侧树状
     */
    @GetMapping("/treeData")
    @ResponseBody
    public List<Ztree> treeData() {
        List<Ztree> ztrees = new ArrayList<Ztree>();
        Ztree ztree[] = {
                new Ztree((long) 100, (long) 0, "合同管理", "合同管理"),
                new Ztree((long) 101, (long) 100, "合同新签登记", "合同新签登记"),
                new Ztree((long) 102, (long) 100, "合同变更登记", "合同变更登记"),
                new Ztree((long) 103, (long) 100, "合同续签登记", "合同续签登记"),
                new Ztree((long) 104, (long) 100, "合同终止登记", "合同终止登记"),
                new Ztree((long) 105, (long) 100, "合同解除登记", "合同解除登记"),
                new Ztree((long) 106, (long) 100, "合同管理历史", "合同管理历史"),
        };
        for (int i = 0; i < ztree.length; i++) {
            ztrees.add(ztree[i]);
        }
        return ztrees;
    }

    @RequestMapping("/findNewSignEmp")
    @ResponseBody
    public TableDataInfo findNewSignEmp(@RequestParam Map map) {
        Authority authority = authorityService.findAuthorAndIsAdmin();
        startPage();
        return getDataTable(contractManageService.findNewSignEmp(map, authority));
    }

    /**
     * 执行新增登记员工存储过程
     */
    @PostMapping("/addNewSignEmp")
    @ResponseBody
    public BaseResult addNewSignEmp(String allEid) {
        return contractManageService.addNewSignEmp(allEid);
    }


    @RequestMapping("/findManageEmp")
    @ResponseBody
    public TableDataInfo findManageEmp(@RequestParam Map map) {
        Authority authority = authorityService.findAuthorAndIsAdmin();
        startPage();
        return getDataTable(contractManageService.findManageEmp(map, authority));
    }

    /**
     * 执行管理登记员工存储过程
     */
    @PostMapping("/addManageEmp")
    @ResponseBody
    public BaseResult addManageEmp(String allEid, String type) {
        return contractManageService.addManageEmp(allEid, type);
    }


    @RequestMapping("/threeProcedure")
    @ResponseBody
    public BaseResult threeProcedure(String allId, String procedure) {
        return contractManageService.threeProcedure(allId,procedure);
    }
}
